package com.zpc.myvideoserver.common.security.handler;

import com.alibaba.druid.support.json.JSONUtils;
import com.alibaba.fastjson.JSON;
import com.zpc.myvideoserver.common.util.ResponseJson;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * @ClassName : AccessDenieHandler  //类名
 * @Description : 权限不足处理类  //描述
 * @Author : zpc20 //作者
 * @Date: 2023/11/2  8:21
 */
@Component
public class AccessDenieHandler implements AccessDeniedHandler {

    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        response.setStatus(response.SC_FORBIDDEN);
        ResponseJson.SecurityResponse(response,new ResponseJson<>(accessDeniedException.getMessage(),response.SC_FORBIDDEN,null));
    }
}
